import { createInsertSchema, createSelectSchema } from 'drizzle-zod';
import { apps, files, storageConfiguration, users } from './schema';

// id如果是自动生成了，已经不是强制校验了
// 但是邮箱需要一定是email格式，所以要进一步增加限制
export const insertUserSchema = createInsertSchema(users, {
  email: (schema) => schema.email(),
});

// 复用zod
export const updateUserSchema = insertUserSchema.pick({
  id: true,
  email: true,
});

// 查询
export const queryUserSchema = createSelectSchema(users);

export const fileSchema = createSelectSchema(files);

export const filesCanOrderByColumns = fileSchema.pick({
  createdAt: true,
  deletedAt: true,
});

export const createAppSchema = createInsertSchema(apps, {
  name: (schema) => schema.min(3).max(100),
});
